<template>
  <div style="padding: 15px;">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px" :key="formKey">
      <el-form-item label="审批状态" prop="auditStatus">
        <el-radio-group v-model="form.status" @change="funcChangeAuditStatus">
          <el-radio label="1" value="0">通过</el-radio>
          <el-radio label="2" value="1">驳回</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="审批意见" prop="remarks">
        <el-input type="textarea" v-model="form.auditMind"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="funcSubmit">提交</el-button>
        <el-button @click="fucCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { differenceAudit } from "@/api/store";
export default {
  name: "differenceAudit",
  data() {
    return {
      formKey: 0,
      form: {
        code: "",
        status: "1",
        auditMind: "",
      },

      rules: {
        status: [
          { required: true, message: "请选择审批状态", trigger: "blur" },
        ],
      },
      auditMind: [
          { required: true, message: "请输入审批意见", trigger: "blur" },
        ],

    };
  },

  created() {},
  methods: {
    // 初始化移位单code
    getInfo(code) {
      this.$refs.form.resetFields();
      this.form.code = code;
    },
    // 审核状态调整事件
    funcChangeAuditStatus(val){
      // 驳回需要填写审核意见，需要动态添加必填规则
      if(val == '3'){
        this.rules.remarks = this.remarksRule;
      }else{
        delete this.rules.remarks;
      }
      // key改变，key改变vue会默认重新渲染该组件
      ++this.formKey;
    },

    // 移位单审核功能
    funcSubmit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          const url = "/wms/difference/audit";
          // 提交
          differenceAudit(this.form).then((response) => {
            // 审核成功则返回到列表页面
            if(response.status == 0){
              this.$message({message:'操作成功', type:'success'});
              this.$emit("fatherAudit");
            }else{
              // 审核失败提示信息
              this.$message.error(response.msg);
            }
          });
        }
      });
    },

    fucCancel() {
      this.$emit("fatherCancel", "audit");
    },
  },
};
</script>

<style>
.vxe-table .vxe-body--column:not(.col--ellipsis),
.vxe-table .vxe-footer--column:not(.col--ellipsis),
.vxe-table .vxe-header--column:not(.col--ellipsis) {
  padding: 6px 0;
}
.vxe-toolbar {
  padding: 0 0 10px 0;
}
</style>
